package com.atguigu.flink.chapter5.transform;

import org.apache.flink.api.common.typeinfo.Types;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.apache.flink.util.Collector;

/**
 * @Author lizhenchao@atguigu.cn
 * @Date 2020/12/19 14:56
 */
public class Flink03_Transform_FlatMap {
    public static void main(String[] args) throws Exception {
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
        env.setParallelism(1);
        DataStreamSource<Integer> source = env.fromElements(1, 10, 20, 30, 100);
        source
          .flatMap((Integer value, Collector<Integer> out) -> {
              out.collect(value * value);
              out.collect(value * value * value);
          })
          .returns(Types.INT)
          .print();


        env.execute();
    }
}
/*
这些function 都有一个Rich
 */
